package Forms;
import Classes.Grades1;
import Classes.GradesNew;
import Classes.MInterface;
import Classes.Quarter;
import Classes.Subject;
import Classes.User;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Owner
 */
public class _UAdviser extends javax.swing.JFrame {
    static MInterface mi;
    
    static User cUser;
    String port;
    _Login l = new _Login();
    static _UAdmin ad;
    static _UAdviser adv;
    DefaultTableModel dtm;
    ArrayList<Object> list;
    ArrayList<Object> list1;
    ArrayList<Object> subjects = null;
    ArrayList<Object> gradeList1 = null;
    ArrayList<Object> gradeList2 = null;
    ArrayList<Object> quarter = null;
    ArrayList<Object> gen;
    String userID;
    String usertID;
    String sub1;
    String sub2;
    String subres1;
    String subres2;
    String combo;
    String sy;
    String a2;
    int a22;
    String a3;
    int a33;
    String val;
    int val1;
    String idno;
    String name;
    String zz;
    String zz2;
    int f = 1;
    String qid;
    String qname;
    String qstat;
    String ggrade;
    String gquartername;
    String gsubject;
    String jcomboselected;
    String g1;
    String g2;
    String g3;
    String g4;
    int gtot;
    int g11;
    int g22;
    int g33;
    int g44;
    String genave;
    int genave1;

    public _UAdviser(User user, _UAdmin a, MInterface i) {
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        
        initComponents();
        ad = a;
//        adv = b;
        
            cUser = user;
            port = l.serverAdd; 
            mi = i;
        
        try {
            usernameL.setText(user.getName());
            timeL.setText(mi.getCurrentTime());
            dateL.setText(mi.getCurrentDate());
            
            quarter = mi.getList4("quarter","Unlock");
            ArrayList<Quarter> q = new ArrayList<Quarter>();
            for(int x100 = 0; x100 < quarter.size(); x100++) {
            Quarter a1 = (Quarter) quarter.get(x100);
            qid = a1.getid();
            qname = a1.getname();
            qstat = a1.getstatus();
            }
            
           
            
            userID = user.getID();
            usertID = user.getType();
            System.out.println(usertID);
             timeL.setText(mi.getCurrentTime());
            dateL.setText(mi.getCurrentDate());
                
             sy = null;
             
//            if (mi.getCurrentDate().compareTo((mi.get("get-endsy", mi.getCurrentDate(), "")) + "") > 0) {
                sy = mi.getToday() + "-" + mi.getNext();
//            } else if (mi.getCurrentDate().compareTo((mi.get("get-endsy", mi.getCurrentDate(), "")) + "") < 0) {
//                sy = mi.getPast() + "-" + mi.getToday();              
//            }
            
                
            if(usertID.matches("Adviser")){
            list = mi.getList4("gradeManage", userID);
            list1 = mi.getList4("gradeManage", userID);
            
            ArrayList<Grades1> s = new ArrayList<Grades1>();
            for(int x = 0; x < list.size(); x++) {
            Grades1 a1 = (Grades1) list.get(x);
               // System.out.println(list.get(x) + " | " + sy);
                    //s.add((Grades1) list.get(x));
               if(a1.getsection().equals(sy)){
               s.add((Grades1) list.get(x));
               }
              //  s.add((Grades1) list.get(x));
                zz = a1.getsy();
                zz2 = a1.getcname();
              // System.out.println(zz);
             //  System.out.println(zz2);
            }
            
            
             
                 
             dtm = new DefaultTableModel(new String[] {gaGradeTbl.getColumnName(0), gaGradeTbl.getColumnName(1), gaGradeTbl.getColumnName(2), gaGradeTbl.getColumnName(3), gaGradeTbl.getColumnName(4), gaGradeTbl.getColumnName(5), gaGradeTbl.getColumnName(6), gaGradeTbl.getColumnName(7)}, 0);
           
             gaGradeTbl.setModel(dtm);
            
            for(int x = 0; x < s.size(); x++) {
           gaGradeTbl.removeAll();
            dtm.insertRow(x, new Object[] {s.get(x).getidno(),s.get(x).getname(),combo,s.get(x).getfirst(), s.get(x).getsecond(),s.get(x).getthird(),s.get(x).getfourth()});
            }
            
                 
            }else if(usertID.matches("Administrator")){
//            list = mi.getList("gradeManage");
                // list1 = mi.getList1("gradeManage22", userID);
              //  list = mi.getList("gradeManage");
          //  ArrayList<Grades1> s = new ArrayList<Grades1>();
//            for(int x = 0; x < list.size(); x++) {
              //  Grades1 a1 = (Grades1) list.get(x);
               // System.out.println(list.get(x) + " | " + sy);
                    //s.add((Grades1) list.get(x));
               //if(a1.getsection().equals(sy)) s.add((Grades1) list.get(x));
              //  s.add((Grades1) list.get(x));
            
            }
            
            //dtm = new DefaultTableModel(new String[] {gaGradeTbl.getColumnName(0), gaGradeTbl.getColumnName(1), gaGradeTbl.getColumnName(2), gaGradeTbl.getColumnName(3), gaGradeTbl.getColumnName(4), gaGradeTbl.getColumnName(5), gaGradeTbl.getColumnName(6), gaGradeTbl.getColumnName(7)}, 0);
          //  gaGradeTbl.setModel(dtm);
//            for(int x = 0; x < s.size(); x++) {
////                String a = s.get(x).getidno();
////                String a1 = s.get(x).getname(); // name
////                String a2 = s.get(x).getsection();//syname
//                 a2 = s.get(x).getstuID();
//                 a22 = Integer.parseInt(a2);
//                sub2  = s.get(x).getcname();
//                sub1  = s.get(x).getsy();
//               // System.out.println(a2);
//                System.out.println(sub2);
//        System.out.println(sub1);
//              gaGradeTbl.removeAll();
//                dtm.insertRow(x, new Object[] {s.get(x).getidno(),s.get(x).getname(),combo,s.get(x).getfirst(), s.get(x).getsecond(),s.get(x).getthird(),s.get(x).getfourth()});
//           val = s.get(x).getidno();
//           name = s.get(x).getname();
//           
//            }
//            }
            
            
            
             
                 //subjects = mi.getList4("subjectManage", zz);
                subjects = mi.getList3("subjectManage", zz, zz2);
                ArrayList<Subject> s12 = new ArrayList<Subject>();   
                for(int x12 = 0; x12 < subjects.size(); x12++) {
                s12.add((Subject) subjects.get(x12));                
                subres1 = s12.get(x12).getSubjName();
                subres2 = s12.get(x12).getsubID();
                jComboBox1.addItem(subres1);   
            }
                                
              
       

            
//            if (mi.getCurrentDate().compareTo(mi.getEndSy(mi.getCurrentDate())) > 0 || mi.getCurrentDate().compareTo(mi.getEndSummer(mi.getCurrentDate())) > 0) { // after regular s.y
//                jButton29.setEnabled(false); // add grades
//                jButton31.setEnabled(false); // manage grades
//                jButton49.setEnabled(false); // add attendance
//                jButton51.setEnabled(false); // manage attendance                
//            } else if (mi.getCurrentDate().compareTo(mi.getEndSy(mi.getCurrentDate())) < 0 || mi.getCurrentDate().compareTo(mi.getEndSummer(mi.getCurrentDate())) < 0) { // during regular s.y
//                jButton29.setEnabled(true); // add grades
//                jButton31.setEnabled(true); // manage grades
//                jButton49.setEnabled(true); // add attendance
//                jButton51.setEnabled(true); // manage attendane                
//            }
        } catch(Exception e) {
            e.printStackTrace();
        }
        
        ActionListener ac = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    timeL.setText(mi.getCurrentTime());
                    dateL.setText(mi.getCurrentDate());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                
            }
        };
        Timer t = new Timer(1000, ac);
        t.start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        dateL = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        timeL = new javax.swing.JLabel();
        usernameL = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jButton6 = new javax.swing.JButton();
        searchT = new javax.swing.JTextField();
        jScrollPane48 = new javax.swing.JScrollPane();
        gaGradeTbl = new javax.swing.JTable();
        currFld10 = new javax.swing.JLabel();
        jLabel78 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        saveAveB = new javax.swing.JButton();
        saveAveB1 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jButton3 = new javax.swing.JButton();
        jLabel54 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/banner.jpg"))); // NOI18N
        jLabel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        dateL.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        dateL.setText("mm/dd/yy");

        jSeparator1.setForeground(new java.awt.Color(0, 102, 51));

        timeL.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        timeL.setText("hh:mm am/pm");

        usernameL.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        usernameL.setText("username");

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton1.setText("Logout");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTabbedPane1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jButton6.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton6.setText("Search");
        jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton6MouseClicked(evt);
            }
        });

        searchT.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        searchT.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                searchTMouseClicked(evt);
            }
        });
        searchT.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                searchTKeyTyped(evt);
            }
        });

        jScrollPane48.setBackground(new java.awt.Color(255, 255, 255));

        gaGradeTbl.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        gaGradeTbl.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID Number", "Student", "Subject", "1st Grading", "2nd Grading", "3rd Grading", "4th Grading", "Average"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        gaGradeTbl.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gaGradeTblMouseClicked(evt);
            }
        });
        jScrollPane48.setViewportView(gaGradeTbl);

        currFld10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        currFld10.setText("0000");

        jLabel78.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel78.setText("No. of Entries:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setText("Gen. Average");

        jButton2.setText("Compute");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        saveAveB.setText("Save");
        saveAveB.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saveAveBMouseClicked(evt);
            }
        });

        saveAveB1.setText("Cancel");
        saveAveB1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saveAveB1MouseClicked(evt);
            }
        });

        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jButton3.setText("ADD");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel54.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel54.setText("Subject:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(222, 222, 222)
                .addComponent(jButton6)
                .addGap(30, 30, 30)
                .addComponent(jLabel54)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(792, 792, 792))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel78)
                .addGap(7, 7, 7)
                .addComponent(currFld10)
                .addGap(607, 607, 607)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveAveB)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(saveAveB1)))
                .addGap(422, 422, 422))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane48)
                .addContainerGap())
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(searchT, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(1173, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton6)
                    .addComponent(jLabel54)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane48, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel78)
                        .addComponent(currFld10)
                        .addComponent(jButton2))
                    .addComponent(jLabel7))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(saveAveB, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(saveAveB1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(16, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(searchT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(470, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("Student, Grades and Attendance", jPanel1);

        jSeparator2.setForeground(new java.awt.Color(0, 102, 51));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 1004, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(10, 10, 10)
                            .addComponent(dateL)
                            .addGap(53, 53, 53)
                            .addComponent(timeL)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(usernameL)
                            .addGap(18, 18, 18)
                            .addComponent(jButton1))
                        .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 1002, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dateL)
                    .addComponent(timeL)
                    .addComponent(usernameL)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int x = JOptionPane.showConfirmDialog(null,"Are you sure you want to logout already?","Alert!",JOptionPane.YES_NO_OPTION);        
        if(x == JOptionPane.YES_OPTION){
            try {
                mi.logout(cUser.getUsername());
                this.setVisible(false);
                new _Login().setVisible(true);
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
       jcomboselected = jComboBox1.getSelectedItem().toString();
        
       try {
            int looper = 0;
            int first1 = 0;
            double first2 = 0;

            ArrayList<Grades1> s1 = new ArrayList<Grades1>();
            for (int x1 = 0; x1 < list1.size(); x1++) {
                Grades1 a1 = (Grades1) list1.get(x1);
                if (a1.getsection().equals(sy)) {
                    s1.add((Grades1) list1.get(x1));
                }

            }
            
            if(qname.equalsIgnoreCase("1st Grading")){
                for (int x1 = 0; x1 < s1.size(); x1++) {
                a3 = s1.get(x1).getstuID();
                a33 = Integer.parseInt(a3);
                 System.out.println(first2);
            System.out.println(a33);
            System.out.println(jcomboselected);
            System.out.println(sy);
                String first = (String) gaGradeTbl.getValueAt(looper, 2);
                first2 = Double.parseDouble(first);
                mi.addGrade(first2,a33,1,jcomboselected,sy);
                looper++;
                JOptionPane.showMessageDialog(null, "Grade Successfully Added", "OK", 1);
                          
               //jComboBox1.removeItem(combo);
            }
            }else if(qname.equalsIgnoreCase("2nd Grading")){
                for (int x1 = 0; x1 < s1.size(); x1++) {
                a3 = s1.get(x1).getstuID();
                a33 = Integer.parseInt(a3);
                
                String first = (String) gaGradeTbl.getValueAt(looper, 3);
                first2 = Double.parseDouble(first);
                mi.addGrade(first2,a33,2,jcomboselected,sy);
                looper++;
                JOptionPane.showMessageDialog(null, "Grade Successfully Added", "OK", 1);
                          
               //jComboBox1.removeItem(combo);
            }
            }else if(qname.equalsIgnoreCase("3rd Grading")){
            for (int x1 = 0; x1 < s1.size(); x1++) {
                a3 = s1.get(x1).getstuID();
                a33 = Integer.parseInt(a3);
    
                String first = (String) gaGradeTbl.getValueAt(looper, 4);
                first2 = Double.parseDouble(first);
                mi.addGrade(first2,a33,3,jcomboselected,sy);
                looper++;
                JOptionPane.showMessageDialog(null, "Grade Successfully Added", "OK", 1);
            
             //jComboBox1.removeItem(combo);
            }
            }else if(qname.equalsIgnoreCase("4th Grading")){
            for (int x1 = 0; x1 < s1.size(); x1++) {
                a3 = s1.get(x1).getstuID();
                a33 = Integer.parseInt(a3);
                
                String first = (String) gaGradeTbl.getValueAt(looper, 3);
                first2 = Double.parseDouble(first);
                mi.addGrade(first2,a33,f,jcomboselected,sy);
                looper++;
                JOptionPane.showMessageDialog(null, "Grade Successfully Added", "OK", 1);
 
               //jComboBox1.removeItem(combo);
            }
            }

            

            
            
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Error", "Error", 0);
            System.out.println(e);
        }
    }//GEN-LAST:event_jButton3MouseClicked

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        
        try{    
            combo = (String) jComboBox1.getSelectedItem();
          ArrayList<Grades1> s = new ArrayList<Grades1>();
        for (int x = 0; x < list.size(); x++) {
            Grades1 a = (Grades1) list.get(x);
            // System.out.println(list.get(x) + " | " + sy);
            //s.add((Grades1) list.get(x));
            if (a.getsection().equals(sy)) {
                s.add((Grades1) list.get(x));
            }
            //  s.add((Grades1) list.get(x));

        }
        dtm = new DefaultTableModel(new String[]{gaGradeTbl.getColumnName(0), gaGradeTbl.getColumnName(1), gaGradeTbl.getColumnName(2), gaGradeTbl.getColumnName(3), gaGradeTbl.getColumnName(4), gaGradeTbl.getColumnName(5), gaGradeTbl.getColumnName(6), gaGradeTbl.getColumnName(7)}, 0);
        gaGradeTbl.setModel(dtm);
        for (int x = 0; x < s.size(); x++) {
//                String a = s.get(x).getidno();
//                String a1 = s.get(x).getname(); // name
//                String a2 = s.get(x).getsection();//syname
            sub2 = s.get(x).getcname();
            sub1 = s.get(x).getsy();

            gaGradeTbl.removeAll();
            dtm.insertRow(x, new Object[]{s.get(x).getidno(), s.get(x).getname(), combo, s.get(x).getfirst(), s.get(x).getsecond(), s.get(x).getthird(), s.get(x).getfourth()});
            val = s.get(x).getidno();
            gradeList2 = mi.getList4("gradeManage1",val);
                ArrayList<GradesNew> uu1 = new ArrayList<GradesNew>();
                for (int x11 = 0; x11 < gradeList2.size(); x11++) {
                    uu1.add((GradesNew) gradeList2.get(x11));
                    ggrade = uu1.get(x11).getgrade();
                    gquartername = uu1.get(x11).getquartername();
                    gsubject = uu1.get(x11).getsubject();
                      if(gquartername.equals("First Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
                    for (int x111 = 0; x111 < uu1.size(); x111++) {
                    dtm.setValueAt(ggrade, x, 2);
                    g1 = (String) dtm.getValueAt(x, 2);
                g11 = Integer.parseInt(g1);
                }
                }else if(gquartername.equals("Second Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
                for (int x111 = 0; x111 < uu1.size(); x111++) {
                    dtm.setValueAt(ggrade, x, 3);
                     g2 = (String) dtm.getValueAt(x, 3);
                g22 = Integer.parseInt(g2);
                }
                }else if(gquartername.equals("Third Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
                for (int x111 = 0; x111 < uu1.size(); x111++) {
                    dtm.setValueAt(ggrade, x, 4);
                    g3 = (String) dtm.getValueAt(x, 4);
                g33 = Integer.parseInt(g3);
                }
                }else if(gquartername.equals("Fourth Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
                for (int x111 = 0; x111 < uu1.size(); x111++) {
                    dtm.setValueAt(ggrade, x, 5);
                    g4 = (String) dtm.getValueAt(x, 5);
                g44 = Integer.parseInt(g4);
                }
                
                }
                      gtot = (g11+g22+g33+g44)/4;
                dtm.setValueAt(gtot, x, 6);
              
                }
                
              
                
                
        }
        
        }catch(Exception e){
        
        }
  

      
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void saveAveB1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveAveB1MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_saveAveB1MouseClicked

    private void saveAveBMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveAveBMouseClicked
//        String genA = genAveTF.getText().trim();
//        double genA1 = Double.parseDouble(genA);
//        DecimalFormat df = new DecimalFormat("#.##");
//        String genA2 = df.format(genA1);  
////        int adad = 0;
////        int t2=0;
////        String t4 = null;
//        try{   
////              testing = new ArrayList<String>();
////            for(int t1 = 0;t1 < 74;t1++){
////             t2 = t2+1;
////             
////             t4 = String.valueOf(t2);
////             testing.add(t4);
////             
////         }
////            
////         
////         a1000 = new ArrayList<Grades1>();
////         testing1 = new ArrayList<String>();
////         for(int x111 = 0; x111 < gradeList1.size(); x111++) {
////         a1000.add((Grades1) gradeList1.get(x111));
////         a100 = a1000.get(x111).getave();
////         adad = Integer.parseInt(a100);
////         testing1.add(a100);
////         
////         }
////         System.out.println(testing1);
////         System.out.println(testing);
////         
////         boolean contains = false;
////        for(int z = 0; z < testing.size(); z++){
////          aqe = testing.get(z).toString();
////          if(testing1.get(z).equals(aqe)){
////              contains = true;
////          }
////        }
////        
////         if(contains = true){
////             JOptionPane.showMessageDialog(null, "Error", "Error", 0);
////         }else if (contains = false) {
////         
////            mi.addgenAve(genA1, aabe, aabe3, aabe2, cUser);
////            JOptionPane.showMessageDialog(null, "GenAve Successfully Added", "OK", 1);
////         
////         }
//       
//            mi.addgenAve(genA2, aabe, aabe3, aabe2, cUser);
//            JOptionPane.showMessageDialog(null, "GenAve Successfully Added", "OK", 1);
//         
//       
////         if(contains == true){
////           JOptionPane.showMessageDialog(null, "Student has a grade below 75 he/she should repeat", "Error", 0);
////             
////           }else  { 
////            mi.addgenAve(genA1, aabe, aabe3, aabe2, cUser);
////            JOptionPane.showMessageDialog(null, "GenAve Successfully Added", "OK", 1);
////               
////           }
////         
//          
//         
//         
//            
//      
//        }catch(Exception e){
//            
//            System.out.println(e);
//        }
//        
    }//GEN-LAST:event_saveAveBMouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

   }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        //  genAveTF.setText(a99);
    }//GEN-LAST:event_jButton2MouseClicked

    private void gaGradeTblMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gaGradeTblMouseClicked

//        if (evt.getClickCount() == 2) {
//
//            int x = gaGradeTbl.getSelectedColumn();
//            while (x != 0) {
//                x--;
//            }
//            int y = gaGradeTbl.getSelectedRow();
//            val = (String) gaGradeTbl.getValueAt(y, x);
//            val1 = Integer.parseInt(val);
//            try {
////           
//                 gradeList2 = mi.getList4("gradeManage1",val);
//                ArrayList<GradesNew> uu1 = new ArrayList<GradesNew>();
//                for (int x11 = 0; x11 < gradeList2.size(); x11++) {
//                    uu1.add((GradesNew) gradeList2.get(x11));
//                    ggrade = uu1.get(x11).getgrade();
//                    gquartername = uu1.get(x11).getquartername();
//                    gsubject = uu1.get(x11).getsubject();
//
//                }
//                
//                if(gquartername.equals("First Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
//                    for (int x11 = 0; x11 < uu1.size(); x11++) {
//                    dtm.setValueAt(ggrade, y, 3);
//                }
//                }else if(gquartername.equals("Second Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
//                for (int x11 = 0; x11 < uu1.size(); x11++) {
//                    dtm.setValueAt(ggrade, y, 4);
//                }
//                }else if(gquartername.equals("Third Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
//                for (int x11 = 0; x11 < uu1.size(); x11++) {
//                    dtm.setValueAt(ggrade, y, 5);
//                }
//                }else if(gquartername.equals("Fourth Grading") && gsubject.equals(jComboBox1.getSelectedItem())){
//                for (int x11 = 0; x11 < uu1.size(); x11++) {
//                    dtm.setValueAt(ggrade, y, 6);
//                }
//                }
//
////                for (int x11 = 0; x11 < uu1.size(); x11++) {
////                    gaGradeTbl.removeAll();
////                    dtm.insertRow(x11, new Object[]{val, name, uu1.get(x11).getsubject(), uu1.get(x11).getfirst(), uu1.get(x11).getsecond(), uu1.get(x11).getthird(), uu1.get(x11).getfourth()});
////
////                }
//                
//                
//            } catch (Exception e) {
//            }
//        }

//        if(evt.getClickCount() == 2) {
//             jComboBox1.removeAllItems();
//            editB.setVisible(true);
//            clearB.setVisible(true);
//            saveB.setVisible(false);
//            jTextField2.setEnabled(true);
//            jTextField3.setEnabled(true);
//            jTextField4.setEnabled(true);
//            jTextField5.setEnabled(true);
//            int x = gaGradeTbl.getSelectedColumn();
//            while(x != 0) {
//                x--;
//            }
//            
//            int y = gaGradeTbl .getSelectedRow();
//            String val1 = (String) gaGradeTbl.getValueAt(y, x);
//            String val2 = (String) gaGradeTbl.getValueAt(y, 1);
//            String val3 = (String) gaGradeTbl.getValueAt(y, 2);
//            String val4 = (String) gaGradeTbl.getValueAt(y, 3);
//            String val5 = (String) gaGradeTbl.getValueAt(y, 4);
//            String val6 = (String) gaGradeTbl.getValueAt(y, 5);
//     
//           
//            
//            jComboBox1.addItem(val1);
//            jComboBox1.setEnabled(false);
//            try {  
//    
//             
//             jPanel1.setVisible(true);
//             editB.setVisible(true);
//             clearB.setVisible(true);
//             jButton3.setVisible(true);
//             
//             
//             jTextField2.setText(val2);
//             jTextField3.setText(val3);
//             jTextField4.setText(val4);
//             jTextField5.setText(val5);
//             jTextField7.setText(val6); 
//            }catch (Exception e) {
//                System.out.println(e);
//                JOptionPane.showMessageDialog(null, e.getMessage());
//                
//            }    
//        }
    }//GEN-LAST:event_gaGradeTblMouseClicked

    private void searchTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchTKeyTyped
        // TODO add your handling code here:
//        String s = "[a-zA-Z0-9\\._\\-]{3,}";
//        char c = evt.getKeyChar();
//    
//        if(c == KeyEvent.VK_SPACE) {
//            if(searchT.getText().isEmpty()) {
//                evt.consume();
//                JOptionPane.showMessageDialog (null, "Space bar not allowed as first character.", "Error", JOptionPane.ERROR_MESSAGE);
//            }
//    }


  }//GEN-LAST:event_searchTKeyTyped

    private void searchTMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_searchTMouseClicked
//        searchT.setText("");
//        searchT.setForeground(Color.black);
    }//GEN-LAST:event_searchTMouseClicked

    private void jButton6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton6MouseClicked
//       try {
//            list = mi.getList("gradeManage");
//            ArrayList<Grades1> s = new ArrayList<Grades1>();
//            String str = searchT.getText().toLowerCase();
//            for(int x = 0; x < list.size(); x++) {
//                Grades1 ss = (Grades1) list.get(x);
//                if(ss.getidno().toLowerCase().contains(str) || ss.getname().toLowerCase().contains(str) || ss.getclasslevel().toLowerCase().contains(str) || ss.getsection().toLowerCase().contains(str) || ss.getsy().toLowerCase().contains(str) || ss.getcname().toLowerCase().contains(str)) {
//                    s.add(ss);
//                }
//            }
//
//            jLabel4.setText(s.size() + "");
//            DefaultTableModel dtm = new DefaultTableModel(new String[] {gaGradeTbl1.getColumnName(0), gaGradeTbl1.getColumnName(1), gaGradeTbl1.getColumnName(2), gaGradeTbl1.getColumnName(3), gaGradeTbl1.getColumnName(4), gaGradeTbl1.getColumnName(4)}, 0);
//            gaGradeTbl1.setModel(dtm);
//            for(int x = 0; x < s.size(); x++) {
//                dtm.insertRow(x, new Object[] {s.get(x).getidno(),s.get(x).getname(), s.get(x).getclasslevel(), s.get(x).getsection(),  s.get(x).getsy(), s.get(x).getcname()});
//            }       
//        } catch(Exception e) {
//            e.printStackTrace();
//        }
    }//GEN-LAST:event_jButton6MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(_UAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(_UAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(_UAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(_UAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new _UAdviser(cUser, ad, mi).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel currFld10;
    private javax.swing.JLabel dateL;
    private javax.swing.JTable gaGradeTbl;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton6;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel54;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel78;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane48;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton saveAveB;
    private javax.swing.JButton saveAveB1;
    private javax.swing.JTextField searchT;
    private javax.swing.JLabel timeL;
    private javax.swing.JLabel usernameL;
    // End of variables declaration//GEN-END:variables
}
